package com.dmai.aiet.epc.archive.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dmai.aiet.epc.archive.base.PageResult;
import com.dmai.aiet.epc.archive.entity.Users;
import com.dmai.aiet.epc.archive.mapper.UsersDao;
import com.dmai.aiet.epc.archive.service.UsersService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersDao usersDao;


    /**
     * 查询记录
     *
     * @param id
     * @return
     */
    public Users findById(String id) {
        return usersDao.findById(id);
    }

    /**
     * 分页
     *
     * @param params
     * @return
     */
    public PageResult<Users> pageAll(Map<String, Object> params) {
        Page<Users> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
        List<Users> list = usersDao.pageAll(page, params);
        long total = page.getTotal();
        if (total > 0) {

        }
        return PageResult.<Users>builder().data(list).code(0).count(total).build();
    }

    /**
     * 列表
     *
     * @param params
     * @return
     */
    public List<Users> findAll(Map<String, Object> params) {
        return usersDao.findAll(params);
    }

}
